#include "dialogvol.h"
#include "ui_dialogvol.h"

DialogVol::DialogVol(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogVol)
{
    ui->setupUi(this);
}

DialogVol::~DialogVol()
{
    delete ui;
}

void DialogVol::on_checkBox_stateChanged(int arg1)
{
    if(arg1 == Qt::Checked)
        ui->SoundVol->setValue(0);
    else {
        ui->SoundVol->setValue(10);
    }
}

void DialogVol::initVol(int v)
{
    ui->SoundVol->setValue(v);
    ui->labelVol->setText(QString::number(v)+"%");
}

void DialogVol::on_SoundVol_valueChanged(int value)
{
    ui->checkBox->setChecked(value == 0);
    ui->labelVol->setText(QString::number(value)+"%");
    emit setvol(value);
}

bool DialogVol::event(QEvent *event)
{
    if (event->type() == QEvent::ActivationChange)
    {
        if(QApplication::activeWindow() != this)
        {
            this->close();
        }
    }
    return QWidget::event(event);
}
